﻿<UserControl x:Class="OneStopProgrammingMatrix.Views.AddNewItem"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:conv="clr-namespace:OneStopProgrammingMatrix.Converters"
             xmlns:cutilctrl="clr-namespace:CommonUtilities.Controls;assembly=CommonUtilities"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="500">
    <UserControl.Resources>
        <conv:ExtractFileNameConverter x:Key="ExtractFileNameConverter" />
        <conv:VisibilityConverter x:Key="VisibilityConverter" />
    </UserControl.Resources>

    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Center" MinWidth="250">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100" />
            <ColumnDefinition />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.Resources>
            <Style x:Key="LabelStyle" TargetType="Label" BasedOn="{StaticResource DefaultLabelStyle}">
                <Setter Property="HorizontalAlignment" Value="Right" />
            </Style>
            <Style x:Key="ControlStyle" TargetType="FrameworkElement">
                <Setter Property="Margin" Value="1,2" />
            </Style>
            <Style x:Key="FieldStyle" TargetType="TextBox" BasedOn="{StaticResource ControlStyle}">
                <Setter Property="Background" Value="LightYellow" />
                <Setter Property="Foreground" Value="Purple" />
            </Style>
        </Grid.Resources>

        <Border Name="brdTitle" Grid.Row="0" Grid.ColumnSpan="3" Style="{StaticResource TitleBackgroundStyle}">
            <TextBlock Name="txtbTitle" Text="{Binding UpdateMode, StringFormat='\{0\} matrix item..', FallbackValue='Add/ Edit'}" Style="{StaticResource TitleTextStyle}" />
        </Border>

        <Label Name="lblMatrixItem" Grid.Row="1" Content="Select to edit :" FontWeight="Bold" Style="{StaticResource LabelStyle}" 
               Visibility="{Binding IsEditMode, Converter={StaticResource VisibilityConverter}, ConverterParameter=C}" />
        <ComboBox Name="cmbMatrixItem" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Style="{StaticResource ControlStyle}" 
                  ItemsSource="{Binding AllMatrixItems}" SelectedItem="{Binding SelectedMatrixItem, Mode=TwoWay}"
                  Visibility="{Binding IsEditMode, Converter={StaticResource VisibilityConverter}, ConverterParameter=C}">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Name="txtbMatrixItemDetails">
                        <TextBlock.Text>
                            <MultiBinding StringFormat="Name : {0} | Desc : '{1}'">
                                <Binding Path="Name" />
                                <Binding Path="Description" />
                            </MultiBinding>
                        </TextBlock.Text>
                    </TextBlock>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>

        <Label Name="lblPath" Grid.Row="2" Content="Path :" Style="{StaticResource LabelStyle}" />
        <cutilctrl:CUtil_WatermarkTextBox Name="txtPath" Grid.Row="2" Grid.Column="1" IsReadOnly="True" 
                                          Style="{StaticResource FieldStyle}" TextAlignment="Left" Foreground="Black"
                                          Text="{Binding NewItem.Path, Converter={StaticResource ExtractFileNameConverter}}" 
                                          WatermarkText="&lt;Select path&gt;" WatermarkAlignment="Left">
            <cutilctrl:CUtil_WatermarkTextBox.ToolTip>
                <TextBlock Text="{Binding NewItem.Path}" />
            </cutilctrl:CUtil_WatermarkTextBox.ToolTip>
        </cutilctrl:CUtil_WatermarkTextBox>
        <Button Grid.Row="2" Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Center" Content=".."
                Width="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=ActualHeight}"
                Command="{Binding BrowsePathCommand}">
            <Button.Style>
                <Style TargetType="Button" BasedOn="{StaticResource ControlStyle}">
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Opacity" Value="1" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="False">
                            <Setter Property="Opacity" Value="0.4" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </Button.Style>
        </Button>

        <Label Name="lblName" Grid.Row="3" Content="Name :" Style="{StaticResource LabelStyle}" />
        <cutilctrl:CUtil_WatermarkTextBox Name="txtbName" Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" Text="{Binding NewItem.Name}" 
                 Style="{StaticResource FieldStyle}" WatermarkText="&lt;Enter name&gt;" />

        <Label Name="lblGroup" Grid.Row="4" Content="Group :" Style="{StaticResource LabelStyle}" />
        <UniformGrid Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" Columns="2">
            <ComboBox Name="cmbGroup" ItemsSource="{Binding AllGroups}"
                      IsEnabled="{Binding IsGroupSelectionEnabled}" SelectedItem="{Binding SelectedGroup, Mode=TwoWay}" 
                      Style="{StaticResource ControlStyle}" />
            <cutilctrl:CUtil_WatermarkTextBox Name="txtbGroup" 
                                              Text="{Binding NewItem.MatrixGroup, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                                              Style="{StaticResource FieldStyle}" 
                                              WatermarkText="&lt;Enter group&gt;" />
        </UniformGrid>

        <Label Name="lblDescription" Grid.Row="5" Content="Description :" Style="{StaticResource LabelStyle}" />
        <cutilctrl:CUtil_WatermarkTextBox Name="txtbDescription" Grid.Row="5" Grid.Column="1" Grid.ColumnSpan="2" 
                                          Text="{Binding NewItem.Description}" 
                                          Style="{StaticResource FieldStyle}" 
                                          WatermarkText="&lt;Enter description&gt;" />

        <StackPanel Name="stkButtons" Grid.Row="6" Grid.Column="1" Grid.ColumnSpan="2" Orientation="Horizontal" 
                    HorizontalAlignment="Right" Style="{StaticResource ControlStyle}">
            <Button Name="btnAdd" Content="{Binding UpdateMode, FallbackValue='Add/ Edit'}" Margin="0,0,2.5,0" Command="{Binding AddEditMatrixItemCommand}" />
            <Button Name="btnDelete" Content="Delete" Margin="2.5,0,0,0" Command="{Binding DeleteCommand}" />
            <Button Name="btnCancel" Content="Cancel" Margin="2.5,0,0,0" Command="{Binding CancelCommand}" />
        </StackPanel>
    </Grid>
</UserControl>
